﻿if (window.v == null) var v = window.v = {};
if (window.$v == null) var $v = window.$v = {};
$v.IsDate = function (val, args) {
    var d = Date.ParseEnyFormat(args.Value);
    args.IsValid = (d && d.getFullYear() > 1900 && d.getFullYear() < 2300);
}
$v.Is少于字数 = function (val, args, maxCharCount) {
    args.IsValid = (args.Value.length <= maxCharCount);
}
$v.IsDateBetween = function (val, args, minValue, maxValue, formatCode) {
    var d = Date.ParseEnyFormat(args.Value);
    if (d == null) {
        args.IsValid = false;
    } else {
        var dCode = d.format(formatCode);
        args.IsValid = (dCode >= minValue && dCode <= maxValue);
    }
}

//
$v.IsChecked = function (val, args) {
    var inputCheck = document.all ? document.all[val.controltovalidate] : document.getElementById(val.controltovalidate);
    args.IsValid = (inputCheck.checked == true);
}
$v.IsZoneCheckedOne = function (val, args) {
    //debugger
    var inputCheckZone = document.all ? document.all[val.controltovalidate] : document.getElementById(val.controltovalidate);
    if (inputCheckZone.nextSibling.Refresh) inputCheckZone.nextSibling.Refresh();
    args.IsValid = (inputCheckZone.nextSibling.value != "");
    //$v.IsZoneCheckedOne = function () { }
}

$v.Is正整数 = function (val, args) {
    var value = args.Value;
    args.IsValid = !isNaN(parseInt(value)) && (("" + parseInt(value)) == value) && parseInt(value) > 0;
}
$v.Is整数 = function (val, args) {
    var value = args.Value;
    args.IsValid = !isNaN(parseInt(value)) && (("" + parseInt(value)) == value);
}
//
$v.Is正小数 = function (val, args) {
    var value = args.Value;
    if (value.indexOf(".") != -1) {
        value = value.replace(/0+$/, "");
    }
    var reg = "^[0-9]+(.[0-9]{2})?$";
    args.IsValid = !isNaN(parseFloat(value)) && (value.match(reg) == null ? false : true);
}
//
$v.Is正两位小数 = function (val, args) {
    var value = args.Value;
    var arr = value.split(".");
    var reg = "^[0-9]+(.[0-9]{2})?$";
    var isNum2 = (arr.length == 2 && arr[1].length >= 1 && arr[1].length <= 2) || arr.length == 1;
    args.IsValid = !isNaN(parseFloat(value)) && (value.match(reg) == null ? false : true) && isNum2;
}
//
$v.Is小于100的正小数 = function (val, args) {
    var value = args.Value;
    var reg = "^[0-9]+(.[0-9]{2})?$";
    args.IsValid = !isNaN(parseFloat(value)) && (value.match(reg) == null ? false : true) && (parseFloat(value) <= 100 && (parseFloat(value) >= 0));
}

$v.Is小于10的正小数 = function (val, args) {
    var value = args.Value;
    var reg = "^[0-9]+(.[0-9]{2})?$";
    args.IsValid = !isNaN(parseFloat(value)) && (value.match(reg) == null ? false : true) && (parseFloat(value) <= 10);
}

$v.Is金额 = function (val, args) {
    var value = args.Value;
    var reg = "^[0-9]+(.[0-9]{2})?$";
    args.IsValid = !isNaN(parseFloat(value)) && (value.match(reg) == null ? false : true) && parseFloat(value) >= 0;
}

